package leedcode_path.回溯;

import java.util.ArrayList;
import java.util.List;

public class 电话号码的字母组合 {
    /*
    * 给定一个仅包含数字 2-9 的字符串，返回所有它能表示的字母组合。答案可以按 任意顺序 返回。

给出数字到字母的映射如下（与电话按键相同）。注意 1 不对应任何字母。
示例 1：
输入：digits = "23"
输出：["ad","ae","af","bd","be","bf","cd","ce","cf"]*/
    List<String> res = new ArrayList<String>();
    StringBuffer sb=new StringBuffer();
    String[] numstring={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    public List<String> letterCombinations(String digits) {
        if (digits.length()==0||digits==null){
            return res;
        }
        backtracking(digits,1);
        return res;
    }
    public void backtracking(String digits,int index){
        if (index==digits.length()){
            res.add(new String(sb));
            return;
        }
        int digit=digits.charAt(index)-'0';
        String str=numstring[digit];
        for (int i = 0; i < str.length(); i++) {
            sb.append(str.charAt(i));
            backtracking(digits,index+1);
            sb.deleteCharAt(sb.length()-1);
        }
    }


}
